<!--
 * @Author: zhaoxiangyu@
 * @Date: 2022-02-14 09:04:08
 * @LastEditors: 647355931@qq.com
 * @LastEditTime: 2022-02-14 09:40:32
 * @Description: file content
-->
<script>
    let obj = {
        name: 'mr bai',
        age: 18
    }

    console.log('obj.name ===> ', obj.name)
    // 如果不存在会报错undefined
    console.log('obj.keys ===> ', obj.keys)

    let proxy = new Proxy(obj, {
        get: function (target, key) {
            //target:要拦截的对象
            //key: 修改的属性
            if (target.hasOwnProperty(key)) {
                if (key == 'name') {
                    return "法外狂徒-张三"
                }
            }
            return "18"
        }
    })

    console.log('proxy.name ===> ', proxy.name)
    console.log('proxy.keys ===> ', proxy.keys)
</script>